package com.ilovepostcard;

import com.ilovepostcard.controller.ShareController;
import com.ilovepostcard.data.SendTaskInfo;
import com.ilovepostcard.utils.Constants;
import com.ilovepostcard.utils.ImageUtil;
import com.ilovepostcard.utils.Utils;
import com.ilovepostcard.view.PostcardMainMenu;
import com.mobclick.android.MobclickAgent;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

public class PrintPayConfirmActivity extends MenuActivity {

	TextView id;
	TextView time;
	@Override
    public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_print_payconfirm);
		init();
		
		MobclickAgent.onEvent(this, Constants.COUNT_CREAT_SUCCEED);
	}
	
	private void init()
	{
		id = (TextView)findViewById(R.id.payconfirm_ID);
		time = (TextView)findViewById(R.id.payconfirm_time);
		
		SendTaskInfo task = ShareController.getInstance().getCurrentSendTask();
		
		if(task!=null)
		{
			id.setText(task.orderID+"");
			time.setText(task.printTime);
		}
	}
	public void onBackPressed () 
	{
		Intent intent = new Intent(this,MainActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		this.startActivity(intent);
		
	}
	

	protected void onResume()
	{
		super.onResume();
		MobclickAgent.onResume(this); 
	}
	
	protected void onPause()
	{
		super.onPause();
		MobclickAgent.onPause(this);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		
		if (resultCode != RESULT_OK) 
		{
			Toast.makeText(this, R.string.error_selectImage, Toast.LENGTH_SHORT).show();
			return;
		}
			
		
		Bitmap bm = null;
		Uri uri = null;
		try {
			
			if (requestCode == ImageUtil.GALLERY) {
				uri = data.getData();
				
			} 
	    	else if (requestCode == ImageUtil.CAMERA)
	    	{
	    		uri = ImageUtil.getImageFromCamera(this);
	    	}
		} 
		catch (Exception e) {
			Toast.makeText(this, R.string.error_selectImage, Toast.LENGTH_SHORT).show();
		}
		
		
		if(bm != null || uri!= null)
		{
			Intent intent = new Intent(this, EditImageActivity.class);
			Bundle bundle =new Bundle();
			String from = "camera";
			if(uri != null)
				from = "gallery";
			bundle.putString("type",from);
			bundle.putParcelable("uri", uri);
			
			intent.putExtras(bundle);
	        startActivity(intent);
		}
	
		
	}
}
